<template>
<div class="mine">
    <div class="header">
        <div class="updatetime">{{ nowDate }}</div>
    </div>
    <div class="my">
      <img
      :src="imgurl"
      v-if="imgurl"
      alt=""
      class="avatar"
      width="100"
      height="100"
    />
    <p class="name">{{detail.userName}}</p>
    </div>
    <div class="liebiao" @click="goaddresslist"><van-icon class="icon" name="map-marked" />收货地址管理<van-icon class="zou" name="share-o" /></div>
    <div class="liebiao" @click="goorderlist"><van-icon class="icon" name="invitation" />订单管理<van-icon class="zou" name="share-o" /></div>
    <div class="liebiao" @click="showPopup"><van-icon class="icon" name="browsing-history" />修改密码<van-icon class="zou" name="share-o" /></div>
 <van-popup
  v-model="show"
  closeable
  close-icon="close"
  position="bottom"
  :style="{ height: '40%' }"
>
 <van-field
    v-model="username"
    class="changecode"
    name="用户名"
    label="初始密码"
    placeholder="请输入初始密码"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="password"
    class="changecode"
    type="password"
    name="密码"
    label="修改密码"
    placeholder="请输入修改密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button round block type="info" native-type="submit" @click="onSubmit">提交</van-button>
  </div>
  </van-popup>
    <div class="liebiao"><van-icon class="icon" name="manager" />修改头像</div>
  <van-uploader  :after-read="afterRead"  />
        <div class="liebiao" ><van-icon class="icon" name="setting" />设置<van-icon class="zou" name="share-o" /></div>
<div @click="exit" class="exit">退出</div>
</div>
</template>
<script>
import { removeToken } from '@/util/auth';
import {requireuse,changepre,changecode} from "../../api/reqMine"
import { Toast } from 'vant';
export default {
data() {
return {
    detail:{},
    nowDate: null,
    nowtimer: "",
    imgurl: "",
     show: false,
      username: '',
      password: '',
};
},
computed: {},
watch: {},
methods: {
    async onSubmit(values) {
        const result =await changecode({
         oldPassword:this.username,
          password:this.password,
        })
        console.log(result);
        if(result.code=="success"){
          this.$router.push("/login");
        }else{
          Toast(result.message);
        }
    },
     showPopup() {
      this.show = true;
    },
    goaddresslist(){
        this.$router.push("/showaddress");
    },
    goorderlist(){
        this.$router.push("/order");
    },
async require(){
  const result =await requireuse()
  this.detail=result;
  //  console.log("用户信息",result);
   this.imgurl=this.detail.avatar
},
//时间
 gettime() {
      this.nowDate = new Date().toLocaleString();
    },
    //头像修改
   async afterRead(file) {
    this.imgurl =file.content;
const result = await changepre({
    avatar:this.imgurl,  
       })
      },
  //退出
  exit(){
    removeToken();
    this.$router.push("/login");
  },
},
created() {
    this.require();
    this.nowtimer = setInterval(this.gettime, 1000);
},
mounted() {},
components: {},
};
</script>
<style scoped>
*{
    margin: 0;
    padding: 0;
}
.header{
    width: 100%;
    height: 16px;
    background: rgb(207, 226, 179);
    font-size: 12px;
    text-align: center;
}
.my{
    width: 100%;
    height: 180px;
    background: url("./imgs/bg.png") no-repeat center/cover;
    opacity: 0.8;
    overflow: hidden;
    position: relative;
}
.avatar{
    width: 100px;
    border-radius: 50%;
    display: block;
    margin: 15px auto;
}
.name{
    text-align: center;
    color: aliceblue;
    font-size: 20px;
}
.liebiao{
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #efeeee;
    line-height: 50px;
    text-indent: 3px;
    position: relative;
}
.liebiao .icon{
    font-size:20px;
    margin-right: 20px;
    color: rgb(33, 118, 158);
}
.liebiao .zou{
position: absolute;
right: 20px;
top: 20px;
font-size:20px;
}
.exit{
    margin-top: 30px;
    width: 80%;
    margin-left: 10%;
    height: 50px;
    background: #d6d5d5;
    border-radius: 25px;
    text-align: center;
    line-height: 50px;
    font-size: 20px;
}
.changecode{
  margin-top: 10px;
  height: 50px;
  line-height: 50px;
}
</style>
